package com.platform.framework.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import com.google.common.collect.Lists;
import com.platform.common.config.SystemConfig;
import com.platform.common.utils.JsonUtils;
import com.platform.framework.dao.rights.FwRightUserRepository;
import com.platform.framework.entity.rights.FwRightRole;
import com.platform.framework.service.rights.FwRightRoleService;

@RestController
public class IndexController extends BaseController{

	@Autowired
	SystemConfig systemConfig;
	
	@Autowired
	FwRightRoleService fwRightRoleService;
	
	@Autowired
	FwRightUserRepository fwRightUserRepository;
	
	@RequestMapping("/proxy")
	public ModelAndView testProxy() {
		ModelAndView mv = new ModelAndView("agent");
		return mv;
	}

	@RequestMapping("/appli")
	public ModelAndView htmlapplicationhome(ModelMap model) {
		long total  = fwRightUserRepository.count();//获取所有用户数量
		ModelAndView mv = new ModelAndView("home/application_home");
		mv.addObject("usertotal", total);
		return mv;
	}

	@RequestMapping("/cs")
	public  String home() {
		return "Hello " + systemConfig.getDbType();
	}
	
	@RequestMapping("/nativeQuery")
	public  String nativeQuery() throws Exception {
		@SuppressWarnings("rawtypes")
		List list =fwRightRoleService.findNativeSql();
		return JsonUtils.dealJson(list);
	}
	
	
	@RequestMapping("/roleQuery")
	public  FwRightRole roleQuery(@RequestParam String rolename) throws Exception {
		FwRightRole fwRightRole = fwRightRoleService.findFwRightOrgByName(rolename);
		return fwRightRole;
	}
	
	@RequestMapping("/roleDeal")
	public  String roleDeal() throws Exception {
		fwRightRoleService.saveRole();
		return "事务测试";
	}
	
	/**
	 * 异常统一处理，内部错误，抛出json格式
	 * 
	 * @return
	 */
	@RequestMapping("/er")
	public String error() {
		List<String> list = Lists.newArrayList();
		System.out.println(list.get(1));
		return "";
	}

	/**
	 * 异常统一处理，外部界面错误，未找到sys对应的模板或有sys.html模板但模板内部报错。抛出500异常
	 * 
	 * @return
	 */
	@RequestMapping("/er1")
	public ModelAndView error1() {
		ModelAndView mv = new ModelAndView("sys");
		//List<String> list = Lists.newArrayList();
		//System.out.println(list.get(1));
		return mv;
	}
	

	
	
	/**
	 * 异常统一处理，找不到页面进入抛出404
	 * 
	 * @return
	 */
	@RequestMapping("/index1")
	public ModelAndView welcomejsp(Model model,HttpServletRequest req) {
		ModelAndView mv = new ModelAndView("user/index1");
		return mv;
	}
	
	/**
	 * 进入index2.html模板页面
	 * 
	 * @return
	 **/
	@RequestMapping("/index2")
	public ModelAndView welcome2(Model model) {
		ModelAndView mv = new ModelAndView("index2");
		return mv;
	}
	
	/**
	 * 进入index2.html模板页面
	 * 
	 * @return
	 **/
	@RequestMapping("/index3")
	public ModelAndView welcome3(Model model,HttpServletRequest req) {
		ModelAndView mv = new ModelAndView("index3");
		return mv;
	}
	/**
	 * 进入上传头像模板页面
	 * 
	 * @return
	 **/
	@RequestMapping("/cropbox")
	public ModelAndView cropbox(Model model) {
		ModelAndView mv = new ModelAndView("cropbox");
		return mv;
	}
	
	
  
    @RequestMapping("/hello")  
    public String hello() {  
        return "不验证哦";  
    }
    
    @RequestMapping("/pages")  
    public String pages() {  
        return "也不验证哦";  
    }  
    

  
    
    /**
     * home1页面，标准的增删改按钮+单一查询， 遵循按钮居左，查询居右
     * @param model
     * @return
     */
	@RequestMapping("home1")
	public ModelAndView home1(Model model) {
		ModelAndView mv = new ModelAndView("home1");
		return mv;
	}
    /**
     * home2页面，标准的查询页面+ 导出，定位，单一查询按钮，功能按钮居右。
     * @param model
     * @return
     */
	@RequestMapping("/home2")
	public ModelAndView home2(Model model) {
		ModelAndView mv = new ModelAndView("/home2");
		return mv;
	}
  
	   /**
     * home3页面，标准的高级查询功能，且高级查询永远居右边。单一查询居左边，按钮一次往后排开。
     * @param model
     * @return
     */
	@RequestMapping("/home3")
	public ModelAndView home3(Model model) {
		ModelAndView mv = new ModelAndView("home3");
		return mv;
	}
	 /**
     * home4页面，标准的四方格布局，可让表格和图表能拥有最大的高度。
     * @param model
     * @return
     */
	@RequestMapping("home4")
	public ModelAndView home4(Model model) {
		ModelAndView mv = new ModelAndView("/home4");
		return mv;
	}
  
	
	 /**
     * home5页面
     * @param model
     * @return
     */
	@RequestMapping("/home5")
	public ModelAndView home5(Model model) {
		ModelAndView mv = new ModelAndView("home5");
		return mv;
	}
	
	/**
     * 个人中心页面
     * @param model
     * @return
     */
	@RequestMapping("personal")
	public ModelAndView personal(Model model) {
		ModelAndView mv = new ModelAndView("personal");
		return mv;
	}
	
	/**
     * 帮助文档页面
     * @param model
     * @return
     */
	@RequestMapping("help")
	public ModelAndView help(Model model) {
		ModelAndView mv = new ModelAndView("help");
		return mv;
	}
	

	/**
     * gist 布局页面
     * @param model
     * @return
     */
	@RequestMapping("home8")
	public ModelAndView home8(Model model) {
		ModelAndView mv = new ModelAndView("home8");
		return mv;
	}
	
	
	/**
     * gist 布局页面
     * @param model
     * @return
     */
	@RequestMapping("buttons")
	public ModelAndView butns(Model model) {
		ModelAndView mv = new ModelAndView("buttons");
		return mv;
	}
	
	
	

}